package com.lagou.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * @author 郑样平
 * @date 2021/5/16  22:23
 */

@Component
public class MyServlet implements ApplicationContextAware {
    private static ApplicationContext context;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

        /**从applicationContext获取DispatcherServlet
         *
         * @return
         */
    public static DispatcherServlet getDispatcherServlet() {
        return context.getBean(DispatcherServlet.class);
    }
}
